package com.totoro.domain.key;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Embeddable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import com.totoro.domain.School;
import com.totoro.domain.Tutor;


@Embeddable
public class SupervisionKey implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@ManyToOne(cascade = { CascadeType.ALL })
	@JoinColumn(name = "school_id", referencedColumnName = "id")
	private School school;// 学院

	@ManyToOne(cascade = { CascadeType.ALL })
	@JoinColumn(name = "tutorSupervision_id", referencedColumnName = "id")
	private Tutor tutorSupervision;// 督导员

	// 空构造器
	public SupervisionKey() {
	}

	public School getSchool() {
		return school;
	}

	public void setSchool(School school) {
		this.school = school;
	}

	public Tutor getTutorSupervision() {
		return tutorSupervision;
	}

	public void setTutorSupervision(Tutor tutorSupervision) {
		this.tutorSupervision = tutorSupervision;
	}

	// 复写hashCode方法
	@Override
	public int hashCode() {
		return getSchool().getId() * 13 + getTutorSupervision().getId();
	}

	// 复写equals方法
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj != null && this.getClass() == obj.getClass()) {
			SupervisionKey target = (SupervisionKey) obj;
			if (getSchool().getId().equals(target.getSchool().getId())
					&& getTutorSupervision().getId().equals(
							target.getTutorSupervision().getId()))
				return true;
		}

		return false;
	}

}
